// LoginDlg.h : interface of the CLoginDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

class CLoginDlg : public CDialogImpl<CLoginDlg>,
					public CToolTipDialog<CLoginDlg>
{
public:
	CLoginDlg(LPCTSTR Name,LPCTSTR Pwd,LPCTSTR Email, bool RememberLogin, bool RememberPwd) : m_Name(Name),m_Pwd(Pwd),m_Email(Email), m_RememberLogin(RememberLogin), m_RememberPwd(RememberPwd)
	{
	}
public:
	enum { IDD = IDD_LOGIN};

	BEGIN_MSG_MAP(CLoginDlg)
		COMMAND_HANDLER(IDC_CHECK_REMEMBER, BN_CLICKED, OnBnClickedCheckRemember)
		COMMAND_HANDLER(IDC_EDIT_PWD, EN_CHANGE, OnEnChangeEditPwd)
		CHAIN_MSG_MAP(CToolTipDialog<CLoginDlg>)

		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		
		COMMAND_ID_HANDLER(IDOK, OnOK)
		COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
	END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	virtual BOOL PreTranslateMessage(MSG* pMsg)
	{
		return CWindow::IsDialogMessage(pMsg);
	}

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		SetWindowLong(GWL_EXSTYLE,GetWindowLong(GWL_EXSTYLE) | WS_EX_LAYERED);
		::SetLayeredWindowAttributes(m_hWnd,0,(255 * 80) / 100,LWA_ALPHA);

		// center the dialog on the screen
		CenterWindow();

		SetDlgItemText(IDC_EDIT_NAME,m_Name);
		SetDlgItemText(IDC_EDIT_PWD,m_Pwd);
		SetDlgItemText(IDC_EDIT_EMAIL,m_Email);

		CheckDlgButton(IDC_CHECK_REMEMBER,m_RememberLogin);
		CheckDlgButton(IDC_CHECK_REMEMBER_PWD,m_RememberPwd);

		if(m_Pwd=="")
			GetDlgItem(IDC_CHECK_REMEMBER_PWD).EnableWindow(FALSE);

		return TRUE;
	}

	LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		GetDlgItemText(IDC_EDIT_NAME,m_Name.GetBuffer(cm::client_server::identify_name_max_length),cm::client_server::identify_name_max_length);
		m_Name.ReleaseBuffer();
		GetDlgItemText(IDC_EDIT_PWD,m_Pwd.GetBuffer(cm::client_server::identify_pwd_max_length),cm::client_server::identify_pwd_max_length);
		m_Pwd.ReleaseBuffer();
		GetDlgItemText(IDC_EDIT_EMAIL,m_Email.GetBuffer(cm::client_server::identify_email_max_length),cm::client_server::identify_email_max_length);
		m_Email.ReleaseBuffer();

		if(IsDlgButtonChecked(IDC_CHECK_REMEMBER))
		{
			m_RememberLogin = true;
			if(IsDlgButtonChecked(IDC_CHECK_REMEMBER_PWD))
				m_RememberPwd = true;
			else
				m_RememberPwd = false;
		}
		else
		{
			m_RememberLogin = false;
			m_RememberPwd = false;
		}

		EndDialog(wID);
		return 0;
	}

	LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		EndDialog(wID);
		return 0;
	}

	LRESULT CLoginDlg::OnBnClickedCheckRemember(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		if(!IsDlgButtonChecked(IDC_CHECK_REMEMBER))		
			CheckDlgButton(IDC_CHECK_REMEMBER_PWD,false);

		return 0;
	}

	LRESULT CLoginDlg::OnEnChangeEditPwd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		// TODO:  If this is a RICHEDIT control, the control will not
		// send this notification unless you override the __super::OnInitDialog()
		// function and call CRichEditCtrl().SetEventMask()
		// with the ENM_CHANGE flag ORed into the mask.

		// TODO:  Add your control notification handler code here

		GetDlgItem(IDC_CHECK_REMEMBER_PWD).EnableWindow(TRUE);

		return 0;
	}

public:
	CString m_Name;
	CString m_Pwd;
	CString m_Email;
	bool m_RememberLogin;
	bool m_RememberPwd;	
};
